package com.huluobo.h3weekdemo.search

import androidx.lifecycle.MutableLiveData
import com.huluobo.h3weekdemo.base.BaseRepo
import com.huluobo.h3weekdemo.main.NewBeanResult
import com.huluobo.h3weekdemo.net.Const
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import retrofit2.http.Query

/**
 *  Created by LC on 2023/11/1.
 */
class SearchRepo : BaseRepo() {
    fun searchNews(
        currentPage: Int,
        id: Int,
        pageSize: Int,
        keyword: String,
        success: MutableLiveData<NewBeanResult>,
        failed: MutableLiveData<String>
    ) {
        getService().searchNews(currentPage, id, pageSize, keyword).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<NewBeanResult> {
                override fun onSubscribe(d: Disposable) {
                }

                override fun onError(e: Throwable) {
                    failed.value = e.message
                }

                override fun onComplete() {
                }

                override fun onNext(t: NewBeanResult) {
                    success.value = t
                }
            })
    }
}